/*<summary>
Created By : Preeti
Created On : 9/20/2008
Class Name : PatientWard_Mapper
Used In    : 
------------------------------------------------------------------------
Modification Log  
------------------------------------------------------------------------
Created By        Modified By         Remarks                             
-----------       ------------        ----------------------------------
                                                                          
------------------------------------------------------------------------
</summary>*/

using System;
using System.Data;
using System.Data.SqlClient;
using System.Data.SqlTypes;
using Utils;

namespace InPatientController
{
    public class PatientWard_Mapper
    {
        public bool Load_PatientWard_DATA(PatientWard objPatientWard)
        {
            if (objPatientWard != null)
            {
                ezUtilsAdapter DBL = new ezUtilsAdapter();
                int ResultVal;
                bool bresult;
                
                try
                {
                    ResultVal = DBL.RunSPReturnInteger("SP_SetPatientWard",
                        new SqlParameter("@biCRNumber", objPatientWard.CRNumber),
                        new SqlParameter("@biWardId", objPatientWard.wardId),
                        new SqlParameter("@biBedId", objPatientWard.bedId),
                        new SqlParameter("@dtStartDate", objPatientWard.startDate));
                    if (ResultVal == 0) { bresult = true; } else { bresult = false; } return bresult;
                }
                catch (SqlException SQLex)
                {
                    string errorMessage = string.Format(
                        "An Error Occurred While Loading the PatientWard Information to the DB. Message: {0}", SQLex.Message);
                    //throw new MappingException(errorMessage, ex);}
                    return false;
                }
                catch (Exception ex)
                {
                    string errorMessage = string.Format(
                        "An Error Occurred While Loading the PatientWard Information to the DB. Message: {0}", ex.Message);
                    //throw new MappingException(errorMessage, ex);}
                    return false;
                }
                finally
                {
                    DBL.Dispose();
                }
            }

            else { return false; }
        }

        public bool Discharge_Patient_Ward(string CRNumber, DateTime dischargeDate)
        {
            ezUtilsAdapter DBL = new ezUtilsAdapter();
            int ResultVal;
            bool bresult;

            try
            {
                ResultVal = DBL.RunSPReturnInteger("SP_DischargePatientWard",
                    new SqlParameter("@biCRNumber", CRNumber),
                    new SqlParameter("@dtEndDate", dischargeDate));
                if (ResultVal == 0) { bresult = true; } else { bresult = false; } return bresult;
            }
            catch (SqlException SQLex)
            {
                string errorMessage = string.Format(
                    "An Error Occurred While Discharging the PatientWard. Message: {0}", SQLex.Message);
                //throw new MappingException(errorMessage, ex);}
                return false;
            }
            catch (Exception ex)
            {
                string errorMessage = string.Format(
                    "An Error Occurred While Discharging the PatientWard. Message: {0}", ex.Message);
                //throw new MappingException(errorMessage, ex);}
                return false;
            }
            finally
            {
                DBL.Dispose();
            }
        }

        public void Dispose()
        {
            this.Dispose(true);
            System.GC.SuppressFinalize(this);
        }

        private void Dispose(bool disposing)
        {
        }


    }
}